<head> 
<script src="/js/jquery-1.4.1min.js" type="text/javascript"> </script>
</head>
<table width='828' border='0' align='center' cellpadding='0' cellspacing='18' bgcolor='#FFFFFF'>
    <tr>
        <td width="250" background="img/bg/left.jpg" valign="top" align="left">
            <img src="img/headings/snabbsok.gif" />
            <div class="search">
                    <form action="" method="post">
                            <input name="search" size="25" value=""/>
                            <button type="submit">S&ouml;k</button>
                    </form>
            </div>

            <img src="img/headings/klimatnyheter.png" /><br/>


<?php /*listNews()*///(SECOND)
    //Testning. Tas bort!!!!!
    //echo $testning[0]['group_id'].'<br/>';    echo count($testning).'<br/>';    echo $testning[1]['group_id'].'<br/>'.'<br/>';for ($i=0; $i<=count($latest)-1; $i++)    {echo $latest[$i]['id'] . "      " . $latest[$i]['title'] . "<br/>";    }
    
    if ($catname)    {
        $catname = $catname[0]['cat'];
        echo "<b>$catname</b><br/>";
    }
    else echo "<b>Alla</b><br/>";
    echo '<div id="newslist">';


    $length = count($title);
    for ($i=0; $i<=$length-1; $i++)
    {     
          echo "<div style=\"padding:4px\"><small>". $date_publishx[$i] ."</small><br/><a href=";
          echo "news/show/";
          echo $query0."/";
          echo $query1."/";
          echo $newsID[$i];
          echo "\><b>" . strip_tags($title[$i]). ". </b>". $text[$i] ." >></a></div>";
    }
    if( $length == 0 )
    echo "Inga nyheter i denna kategorien, kategorin kanske inte finns.";


    if (strlen($ingaNyheter) == 0) {
    echo $ingaNyheter;
    }
    if (strlen($searchFail) == 0) {
    echo $searchFail;
    }
    if ($needLink) {
    echo  "<br/><div style=\"text-align:right\" id=\"expander\"><a href=\"javascript:expand_news(2);\">Fler nyheter &gt;&gt;</a></div>";

    }
?>
    <script type="text/javascript">
        function expand_news(offset)
        {

            //this should work with jquery!!!
            $('#expander').click($('#newslist').get('localhost/testmvc/show/expand/', {offset: 2}, function(data){
            $('#newslist').html(data);
                }
            ))
        }

    </script>
 		<script type="text/javascript">
			function expand_news(offset) {
				expander.innerHTML = '<img src="img/ajax-loader.gif" alt="H�mtar nyheter..."/>'
				var hr = new ajaxRequest("localhost/testmvc/news/expand.php/<?php echo $query0?>/<?php if (isset($query1)) echo $query1?>/<?php echo $query2?>/"+offset);
				hr.actions = function() {
					newslist.innerHTML = hr.responseText;
				};
				hr.send();
                                }
                </script>
			
		
        

        </td>
        <td width="526" valign='top' align="left" style="background:url('img/bg/main2.jpg') repeat-y">

            <img src="img/headings/smartakategorier.png"/>
            <table style="width:100%;margin:5px 5px 0 5px;">
                <tr>
                    <td align="left" valign="top">






<?php
//-----
//THIRD
//listCat()

//Test för att lopa ut alla kategorier
//for ($i=0; $i<=count($getcategories)-1; $i++){echo $getcategories[$i]['cat'] . '<br />';} echo '<br/>'.'<br/>'.'<br/>'.'<br/>';


    //echo "<a href=\"".niceLinks("?page=news", $linkNice)."\">";
    if (!$catname) echo "<b>Alla</b>";
    else echo "Alla";
    echo "</a><br/>";
    $length = count($getcategories);
    $multiplier = ceil(($length+1) /4); //+1 f�r att Alla ska f� plats
    $b = 1; //f�r att Alla ska ta plats
    $breakpoint = $multiplier;

    $gc = $getcategories;
    for ($i=0; $i<=$length-1; $i++)
    {
        $b++;
        if ($b > $breakpoint) {
                echo "</td><td align=\"left\" valign=\"top\">";
                $breakpoint = $breakpoint + $multiplier;
        }
        //echo "<a href=\"".niceLinks("?page=news&cat=".substr($gc[$i]['number'],0,-2), $linkNice)."\">";
        if (isset($low) && isset($high) && $gc[$i]['number'] >= $low && $gc[$i]['number'] < $high) echo "<b>" . $gc[$i]['cat'] . "</b>";
        else
        {
            if (strlen($gc[$i]['number']) == 4)
            {
                $rc = 2;
            }
            else
            {
                $rc = 1;
            }

            echo "<a href='news/show/";
            echo substr($gc[$i]['number'], 0, $rc);
            echo "/'>";
            echo $gc[$i]['cat'];
            echo "</a>";
        }
        echo "</a><br/>";
        
    }
//THIRD
//-----
?>

                    </td>
                </tr>
            </table>

            <div style="padding:0 4px 4px 4px">

                <small>
<!-- fourth -->
<?
//------
//FOURTH

    $currentcat = '';
    $recent = false;

    $gc = $getcats;
    $first = true;
    
    //echo "<div class=\"hr\">här ska det vara ett fint blått sträck!</div>";
    for ($i=0; $i<=count($gc)-1; $i++)
    {
        if ($gc[$i]['number'] >= 1000 )
        {
            $step = 2;
            $sp = 2;
        }
        else
        {
            $step = 1;
            $sp = 1;
        }

        $tempCat = substr($gc[$i]['number'], 0, $step);
        $tempSub = substr($gc[$i]['number'], $sp, 2);

        if( $currentcat == $gc[$i]['cat'])
        {
            $antalKopior++;
        }
        else
        {
            $antalKopior=1;
            $currentcat = $gc[$i]['cat'];
            $recent = false;
        }
        //skriver ut de kategorier där det finns 3 nyheter som inte är äldre än en månad
        if( $antalKopior >= 3 && $gc[$i]['date_publish'] >= date("Y-m-d H:i:s", strtotime("-1 month")) && !$recent )
        {
            if ($first)
            {
                //Detta ska förmodligen vara en bild?????
                echo "<div style='background:#286F8B; width:520px; height:1px; margin-top: 5px; margin-bottom:5px; float:left'></div>";
            }
                if(!$first)
                {
                    echo " - ";
                }
                $first = false;
                $recent = true;
                $bold = $gc[$i]['cat'];
                if ($category.$sub == $gc[$i]['number']) $bold = "<b>$bold</b>";
                echo "<a href=news/show/$tempCat/$tempSub />$bold</a>";
        }
    }


//  if (isset($subs)) echo "<div class=\"hr\"></div>", implode(" - ", $subs);

//FOURTH
//------
?>



                </small>
            </div>
            <img src="img/headings/bar.png"/>
 
            <div style="padding:5px">

<!-- BARA FÖR ATT SE OM $nonews ÄR TRUE ELLER FALSE! -->
<?//if($nonews){echo "<script> alert('true: inga nyheter') </script>";}if(!$nonews){echo "<script> alert('false: finns nyheter') </script>";}?>

<?
    //
    //http://localhost/testmvc/news/show/12/10/5658
    //echo $latest[0]['mainlink'];

    //-----
    //fifth
    $buffer="";
    //h�r s� blir det fel dag vald!!!

    if (!$nonews) {
    if ($latest[0]['mainlink_activated'])
    {
        $mainlink = $latest[0]['mainlink'];
        $needProtocol = true;

        //om de första 7/8 tecknen inte är http(s):// så läggs det till
        if (substr($mainlink,0,7)=="http://" ) $needProtocol = false;
        elseif( substr($mainlink,0,8)=="https://") $needProtocol = false;
        if ($needProtocol) $mainlink = "http://$mainlink";

        //funkar inte. Skriver ut target="_blank oavsett. Ska det vara === i if-satsen?
        if (strpos($mainlink,"klimatsmart.se") === false) $mainlink .= '" target="_blank';
    }
    echo $mainlink;
    }
?>
<!-- fifth -->



                    <div style="clear:both;margin-top:20px;">
                    <div style='background:#286F8B; width:520px; height:1px; float:left'></div>
                    <div class="hr"></div>
                    <div style="float:right"><a href="www.en_nicelink.com"><small>Vill du synas h&auml;r?</small></a></div>
                    <div style="padding-bottom:0.5em"><small>Relaterade f&ouml;retag/produkter:</small></div>

<!-- sixth -->





<!--SKA KÖRAS SIST!!!!!-->
    <table width="526" border="0" cellspacing="0" cellpadding="0" align="center">
        <?php /*showCompanyAdds() */
        //Test för $cat
        //for ($i=0; $i<=$count($cat); $i++){echo $cat[$i]['cat'];echo ", ";echo $cat[$i]['number'];echo "<br/>";}
        global $server, $serverUsed;

        if ( $list == true )
        {
            echo $categories;

            $length = count($result);
            for ($i=0; $i<=$length-1; $i++)
            {
                echo "<tr>\n";
                echo "<td width=\"270\" style=\"vertical-align:top;padding-right:4px;\">
                        <a href='".$result[$i]['link']."' target='_blank' >
                                <span class=\"style3\" style=\"font-weight:bold;\">".$result[$i]['company']." ".$result[$i]['name']."</span><br />";
                if( strlen($result[$i]['subtext']) > 0)
                                echo "<span class=\"style1\" style=\"font-weight:bold;color:green;\">".htmlspecialchars($result[$i]['subtext'])."</span><br />\n";
                echo "<div style=\"text-align:justify;vertical-align:top;\" class='style1'>".$result[$i]['text']."</div>
                        </a>
                      </td>\n";
                echo "<td width=\"250\"  align='center' valgn='middle'>
                        <a href='".$result[$i]['link']."' target='_blank'>
                                <img src='img/logos/" .$result[$i]['Logo']. "' border='0' alt=\"Logga\" /></a></td>";
                echo "</tr>\n";
                echo "<tr><td style=\"height:0.5em\"></td><td></td></tr>";
            }
        }
        ?>
    </table>
			</div>
			</div>
		</td>
	</tr>
</table>
